package com.masterclient.app.modules.category.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.managerlibrary.netsign.NetEnvManager;
import com.masterclient.app.httpservice.RetrofitUtil;
import com.eoner.baselib.container.CommonBaseResponse;
import com.masterclient.app.modules.category.beans.CategoryAllIndexBean;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
* Created by TMVPHelper on 2017/06/30
*/
public class CategoryPresenter extends CategoryContract.Presenter{

//    @Override
//    public void getCategoryClassOneList() {
//        Observable<CategoryFirstBean> observable = RetrofitUtil.getInstance().getCategoryClassOneList(Config.BASE_SURL+"1/category.html");
//
//        Disposable disposable = toSubscribe(observable, new Consumer<CategoryFirstBean>() {
//            @Override
//            public void accept(@NonNull CategoryFirstBean bean) throws Exception {
//                if("0".equals(bean.getCode())){
//                    mView.showClassOneMenu(bean.getData());
//                }else {
//                    mView.loadFail(bean.getMsg());
//                }
//            }
//        },new ThrowableConsumer(){
//            @Override
//            public void accept(@NonNull Throwable o) throws Exception {
//                super.accept(o);
//                mView.loadError("");
//            }
//        });
//        mRxManager.add(disposable);
//    }
//
//    @Override
//    public void getCategoryBrandList(@android.support.annotation.NonNull String cid) {
//        Observable<CategoryBrandBean> observable = RetrofitUtil.getInstance().getCategoryBrandList(Config.BASE_SURL+"1/category/get_brand_list/cid_"+cid+".html");
//        Disposable disposable = toSubscribe(observable, new Consumer<CategoryBrandBean>() {
//            @Override
//            public void accept(@NonNull CategoryBrandBean bean) throws Exception {
//                if(bean != null && bean.getData()!= null){
//                    mView.showBrandList(bean.getData());
//                }
//            }
//        },new ThrowableConsumer(){
//            @Override
//            public void accept(@NonNull Throwable o) throws Exception {
//                super.accept(o);
//            }
//        });
//        mRxManager.add(disposable);
//    }

    //全品类新增接口，还没替换
    @Override
    public void getCategoryData() {
        Observable<CommonBaseResponse<CategoryAllIndexBean>> observable = RetrofitUtil.getInstance().getCategoryData(NetEnvManager.BASE_SURL+"1/category/all_index.html");

        Disposable disposable = toSubscribe(observable, new Consumer<CommonBaseResponse<CategoryAllIndexBean>>() {
            @Override
            public void accept(@NonNull CommonBaseResponse<CategoryAllIndexBean> bean) throws Exception {
                if(bean.getCode() == 0){
                mView.showData(bean.getData().getSh_categorys());
                }else {
                    mView.loadFail(bean.getMsg());
                }
            }
        },new ThrowableConsumer(){
            @Override
            public void accept(@NonNull Throwable o) throws Exception {
                super.accept(o);
                mView.loadError("网络异常，请重试");
            }
        });
        mRxManager.add(disposable);
    }
}